package ru.spb.osll.myfit.fixtures.base;

import static org.junit.Assert.assertEquals;

import java.io.PrintWriter;

import org.junit.Test;

import ru.spb.osll.myfit.util.StringPrintWriter;
import fit.Fixture;
import fit.FixtureLoader;
import fit.Parse;

public class OneLineFixtureTest {
	private static final String SYSTEM_LINE_SEPARATOR = System
			.getProperty("line.separator");
	private static final String HTML = "<table border=\"1\" cellspacing=\"0\">\n"
		+ "<tr><td class=\"pass\">dummy one line</td>\n"
		+ "<td>OK</td>\n</tr>\n</table>\n";

	private static final String HTML2 = "<table border=\"1\" cellspacing=\"0\">\n"
			+ "<tr><td>dummy one line</td>\n"
			+ "<td>up</td>\n<td>and</td>\n<td>running</td>\n"
			+ "</tr>\n</table>\n";

	@Test
	public void testOneLineFixture() throws Exception {
		Parse table = new Parse(OneLineFixtureUtilsTest
				.wiki2html("|dummy one line|OK|"));
		FixtureLoader.instance().addPackageToPath(
				"ru.spb.osll.myfit.fixtures.base");
		Fixture fixture = new Fixture();
		fixture.doTables(table);
		PrintWriter writer = new StringPrintWriter();
		table.print(writer);
		String actual = writer.toString();
		System.out.println(actual);
		String expected = HTML.replace("</td>\n", "</td>"
				+ SYSTEM_LINE_SEPARATOR);
		assertEquals(expected, actual);
	}

	@Test
	public void testOneLineWithArgsFixture() throws Exception {
		Parse table = new Parse(OneLineFixtureUtilsTest
				.wiki2html("|dummy one line|up|and|running|"));
		FixtureLoader.instance().addPackageToPath(
				"ru.spb.osll.myfit.fixtures.base");
		Fixture fixture = new Fixture();
		fixture.doTables(table);
		PrintWriter writer = new StringPrintWriter();
		table.print(writer);
		String actual = writer.toString();
		System.out.println(actual);
		String expected = HTML2.replace("</td>\n", "</td>"
				+ SYSTEM_LINE_SEPARATOR);
		assertEquals(expected, actual);
	}
}
